<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Rep\MaterialRep;
use Illuminate\Http\Request;

class Material extends Controller
{
    //材料列表
    protected $rep;

    public function __construct(Request $request)
    {
        $this->rep = new MaterialRep();
    }

    /**
     * @param Request $request
     */
    public function getMaterialList(Request $request){
        $params = $request->all();
        $data = $this->rep->getMaterialListRep($params);
        return re(0,$data,'success');
    }

    /**
     * @param Request $request
     */
    public function createMaterial(Request $request){
        $params = $request->only(['id','name','code','type_id','model_number','specification','color','product_ids','unit','supplier_id','w_price','initial_min','initial_max','warehouse_id']);
        $data = $this->rep->createMaterialRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delMaterial(Request $request){
        $params = $request->all();
        $data = $this->rep->delMaterialRep($params);
        return re($data['code']);
    }

    /**
     * 获取材料库存数
     * @return void
     */
    public function getMaterialStock(Request $request){
        $material_id = $request->input('material_id');
        $data = $this->rep->getMaterialStockRep($material_id);
        return re(0,$data,'success');
    }
}
